Memory Management Chatbot

Quality of Code

Criteria Meet Specification

Is the code functional?

The code compiles and runs with cmake and make .

Task 1: Exclusive Ownership 1

Criteria Meet Specification

_chatLogic is an exclusive resource of ChatbotPanelDialog

In file chatgui.h / chatgui.cpp , _chatLogic is made an exclusive resource to class ChatbotPanelDialog using an appropriate smart pointer. Where required, changes are made to the code such that data structures and function parameters reflect the new structure.

Task 2: The Rule of Five

Criteria Meet Specification

Class design meets the Rule of Five guidelines.

In file chatbot.h / chatbot.cpp , changes are made to the class ChatBot such that it complies with the Rule of Five. Memory resources are properly allocated / deallocated on the heap and member data is copied where it makes sense. In each of the methods (e.g. the copy constructor), a string of the type "ChatBot Copy Constructor" is printed to the console so that it is possible to see which method is called in later examples.

Task 3: Exclusive Ownership 2

Criteria Meet Specification

The GraphNode s in the vector _nodes are exclusively owned by the class ChatLogic .

In file chatlogic.h / chatlogic.cpp , the vector _nodes are adapted in a way that the instances of GraphNodes to which the vector elements refer are exclusively owned by the class ChatLogic . An appropriate type of smart pointer is used to achieve this.

GraphNode ownership is not transferred when passing instances.

When passing the GraphNode instances to functions, ownership is not transferred.

Task 4: Moving Smart Pointers

Criteria Meet Specification

GraphNode s exclusively own the outgoing GraphEdges and hold non-owning references to incoming GraphEdges .

In files chatlogic.h / chatlogic.cpp and graphnodes.h / graphnodes.cpp all instances of GraphEdge are changed in a way such that each instance of GraphNode exclusively owns the outgoing GraphEdges and holds non-owning references to incoming GraphEdges . Appropriate smart pointers are used to do this. Where required, changes are made to the code such that data structures and function parameters reflect the changes.

Move semantics are used when transferring ownership from class ChatLogic into instances of GraphNode .

In files chatlogic.h / chatlogic.cpp and graphnodes.h / graphnodes.cpp , move semantics are used when transferring ownership from class ChatLogic , where all instances of GraphEdge are created, into instances of GraphNode .

Task 5: Moving the ChatBot

Criteria Meet Specification

Move semantics are used correctly with ChatBot .

In file chatlogic.cpp , a local ChatBot instance is created on the stack at the bottom of function LoadAnswerGraphFromFile and move semantics are used to pass the ChatBot instance into the root node.

ChatLogic has no ownership relation to the ChatBot instance.

ChatLogic has no ownership relation to the ChatBot instance and thus is no longer responsible for memory allocation and deallocation.

The Chatbot prints output to indicate Rule of Five components.

When the program is executed, messages are printed to the console indicating which Rule of Five component of ChatBot is being called.